package com.yqg.education.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yqg.education.common.Result;

import com.yqg.education.service.IExamHistoryLogService;
import com.yqg.education.entity.ExamHistoryLog;

import org.springframework.web.bind.annotation.RestController;

/**
 * ExamHistoryLogController 前端控制器
 * @author zxf
 * @since 2025-09-11
 */
@RestController
@RequestMapping("//exam-history-log")
public class ExamHistoryLogController {

    @Resource
    private IExamHistoryLogService examHistoryLogService;

    /**
    *  新增或者更新
    */
    @PostMapping("/edit")
    public Result save(@RequestBody ExamHistoryLog examHistoryLog) {
        examHistoryLog.setCreateTime(LocalDateTime.now());
        return Result.success(examHistoryLogService.saveOrUpdate(examHistoryLog));
    }
    /**
    *  删除
    */
    @GetMapping("delete/{id}")
    public Result delete(@PathVariable Integer id) {
        ExamHistoryLog examHistoryLog =examHistoryLogService.getById(id);
        examHistoryLog.setIsDelete(1);
        return Result.success(examHistoryLogService.saveOrUpdate(examHistoryLog));
    }
    /**
    *  查询所有
    */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<ExamHistoryLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", 0);
       List<ExamHistoryLog> list=  examHistoryLogService.list(queryWrapper);
        return Result.success(list);
    }
    /**
    *  根据id查询
    */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(examHistoryLogService.getById(id));
    }
    /**
    *  分页查询
    */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                                @RequestParam Integer pageSize,
                           @RequestParam Long examLogId) {
        QueryWrapper<ExamHistoryLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", 0);
        queryWrapper.eq("exam_log_id", examLogId);
        queryWrapper.orderByDesc("id");
        return Result.success(examHistoryLogService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

}

